package com.kc.zhaojiu.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kc.zhaojiu.entity.TbLeader;
import com.kc.zhaojiu.entity.TbManager;
import com.kc.zhaojiu.entity.TbTeacher;
import com.kc.zhaojiu.service.TbLeaderService;
import com.kc.zhaojiu.service.TbManagerService;
import com.kc.zhaojiu.service.TbTeacherService;
import com.kc.zhaojiu.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * Author: QiongKe~
 * Date: 2022/11/4 22:32
 */
@RestController
@RequestMapping("/Login")
public class LoginController extends BaseController {
    @Autowired
    private TbTeacherService tbTeacherService;

    @Autowired
    private TbLeaderService tbLeaderService;

    @Autowired
    private TbManagerService tbManagerService;

    @PostMapping()
    public JsonResult<Map<String,Object>> login(@RequestBody Map<String,String> map){
        String username = map.get("username");
        String password = map.get("password");
        QueryWrapper<TbTeacher> queryWrapper=new QueryWrapper();
        QueryWrapper<TbLeader> queryWrapper1=new QueryWrapper<>();
        QueryWrapper<TbManager> queryWrapper2=new QueryWrapper<>();
        queryWrapper.eq("worker_id",username).eq("password",password);
        queryWrapper1.eq("worker_id",username).eq("password",password);
        queryWrapper2.eq("worker_id",username).eq("password",password);

        if(tbTeacherService.getMap(queryWrapper)!=null){
            Map<String, Object> data = tbTeacherService.getMap(queryWrapper);
            return new JsonResult<>(OK,data,"登录成功");
        }
        else if(tbLeaderService.getMap(queryWrapper1)!=null){
            Map<String, Object> data = tbLeaderService.getMap(queryWrapper1);
            return new JsonResult<>(OK,data,"登录成功");
        }
        else if(tbManagerService.getMap(queryWrapper2)!=null){
            Map<String, Object> data =tbManagerService.getMap(queryWrapper2);
            return new JsonResult<>(OK,data,"登录成功");
        }



        return new JsonResult<>(OK,null,"未查询到该用户！");
    }

}
